package DevCode.Servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import DevCode.Excepcion.DAOExcepcion;
import DevCode.Modelo.Usuario;
import DevCode.Negocio.GestionComentario;

/**
 * Servlet implementation class GuardarComentarioServlet
 */
@WebServlet("/GuardarComentarioServlet")
public class GuardarComentarioServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GuardarComentarioServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		Usuario usuario_actual = (Usuario)session.getAttribute("USUARIO_ACTUAL");
		int USicodigo = usuario_actual.getUSicodigo();
		int IDicodigo = Integer.parseInt(request.getParameter("IDicodigo"));		
		String COvcomentario = request.getParameter("txtcomentario");

		GestionComentario negocio = new GestionComentario();
		String mensaje="";
		try {		
			System.out.println(COvcomentario+" "+IDicodigo+" "+USicodigo);
			mensaje = negocio.guardarComentario(COvcomentario, IDicodigo, USicodigo);
			request.setAttribute("MENSAJE", mensaje);
			RequestDispatcher rd = request.getRequestDispatcher("DetalleIdeaServlet?id="+IDicodigo);
			rd.forward(request, response);	
		}catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("Error.jsp");
			rd.forward(request, response);
		}
	}

}
